from pyecharts import options as opts
from pyecharts.charts import Pie

# 数据
values = [882, 588]
categories = ["男", "女"]

# 创建饼图
pie = (
    Pie(init_opts=opts.InitOpts(bg_color="#1D244A"))
    .add(
        "",
        [list(z) for z in zip(categories, values)],
        radius=["55%", "70%"],
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="性别", pos_left="center", pos_top="10%",
                                  title_textstyle_opts=opts.TextStyleOpts(color="white")),
        legend_opts=opts.LegendOpts(pos_right="10%", pos_top="center", orient="vertical",
                                    textstyle_opts=opts.TextStyleOpts(color="white")),
    )
    .set_series_opts(
        label_opts=opts.LabelOpts(formatter="{d}%", color="white")
    )
    .set_colors(["#0070C0", "#EDA530"])
)

# 渲染图表
pie.render("sex.html")
